﻿// <copyright file="RaingageLocation.cs" company="City of Portland, BES-ASM">
// </copyright>
// <summary>RaingageLocation class</summary>

namespace BESASM.EMGAATS.BusinessClasses
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;

  /// <summary>
  /// Manages the location of a raingage
  /// </summary>
  public class RaingageLocation : IPoint
  {
    private double x;
    private double y;

    /// <summary>
    /// Initializes a new instance of the <see cref="RaingageLocation"/> class
    /// </summary>
    /// <param name="x">The X-coordinate of the location</param>
    /// <param name="y">The Y-coordinate of the location</param>
    public RaingageLocation(double x, double y)
    {
      this.x = x;
      this.y = y;
    }

    /// <summary>
    /// Gets or sets the X-coordinate of the location
    /// </summary>
    public double X
    {
      get
      {
        return this.x;
      }

      set
      {
        this.x = value;
      }
    }

    /// <summary>
    /// Gets or sets the Y-coordinate of the location
    /// </summary>
    public double Y
    {
      get
      {
        return this.y;
      }

      set
      {
        this.y = value;
      }
    }

    /// <summary>
    /// Equality operator for two raingage locations
    /// </summary>
    /// <param name="a">The first raingage location</param>
    /// <param name="b">The second raingage location</param>
    /// <returns>True if the given raingage locations have the same coordinates</returns>
    public static bool operator ==(RaingageLocation a, RaingageLocation b)
    {
      return (a.X == b.X) && (a.Y == b.Y);
    }

    /// <summary>
    /// Inequality operator for two raingage locations
    /// </summary>
    /// <param name="a">The first raingage location</param>
    /// <param name="b">The second raingage location</param>
    /// <returns>True if the given raingage locations do not have the same coordinates</returns>
    public static bool operator !=(RaingageLocation a, RaingageLocation b)
    {
      return !(a == b);
    }

    /// <summary>
    /// Returns a value indicating if this point has the same coordinates as the given point.
    /// </summary>
    /// <param name="point">The point to compare to this one.</param>
    /// <returns>True if the points are the same, otherwise false.</returns>
    public bool IsEquivalentTo(IPoint point)
    {
      if (point == null)
      {
        return false;
      }

      return this.X == point.X && this.Y == point.Y;
    }

    /// <summary>
    /// Clones a raingage location
    /// </summary>
    /// <returns>A copy of the given raingage location</returns>
    public object Clone()
    {
      return new RaingageLocation(this.x, this.y); 
    }

    /// <summary>
    /// Tests whether the given raingage location is equal to another object
    /// </summary>
    /// <param name="obj">The object to be compared against</param>
    /// <returns>True if the raingage location is equal to the object</returns>
    public override bool Equals(object obj)
    {
      if (obj == null)
      {
        return false;
      }

      RaingageLocation secondPoint = obj as RaingageLocation;
      if ((object)secondPoint == null)
      {
        return false;
      }

      return (this.X == secondPoint.X) && (this.Y == secondPoint.Y);
    }

    /// <summary>
    /// Gets the hash code for the raingage location
    /// </summary>
    /// <returns>The hash code for the raingage location</returns>
    public override int GetHashCode()
    {
      return Tuple.Create(this.X, this.Y).GetHashCode();
    }

    /// <summary>
    /// Gets the string representation of the raingage location
    /// </summary>
    /// <returns>The string representation of the raingage location</returns>
    public override string ToString()
    {
      return string.Format("({0},{1})", this.X, this.Y);
    }
  }
}
